﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Task_WorkTask_WorkTaskList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();
    }

    private void Bind()
    {
        BindYearList();
        for (int i = 1; i <= 12; i++)
        {
            this.DptMonth.Items.Add(new ListItem(i.ToString() + "月", i.ToString()));
        }

        this.DptYear.SelectedValue = DateTime.Now.Year.ToString();
        this.DptMonth.SelectedValue = DateTime.Now.Month.ToString();
        this.BtnQuery_Click(this.BtnQuery, new EventArgs());
    }

    public string GetSubString(object obj, int len)
    {
        if (obj == null)
            return "";
        if (obj.ToString().Length > len)
            return obj.ToString().Substring(0, len)+"...";
        else
            return obj.ToString();
        
    }
    protected void BtnQuery_Click(object sender, EventArgs e)
    {
        string Where = string.Empty;
        if (RdMonth.Checked)
        {
            Where = " Year(TaskDate)='" + this.DptYear.SelectedValue + "' And Month(TaskDate)='" + this.DptMonth.SelectedValue + "'  And IsYear =0 And DepartmentID='"+Session["DepartmentID"].ToString()+"'";
            this.lblTitle.Text = this.DptYear.SelectedItem.Text + this.DptMonth.SelectedItem.Text + "任务列表";
        }
        else
        {
            Where = " Year(TaskDate)='" + this.DptYear.SelectedValue + "' And IsYear =1 And DepartmentID='" + Session["DepartmentID"].ToString() + "'";
            this.lblTitle.Text = this.DptYear.SelectedItem.Text +  "任务列表";
        }
        
        this.GvwList.DataSource = new Yipusoft.WorkTaskGrade.BLL.WorkTaskGrade().GetList(Where);
        this.GvwList.DataBind();
    }
    protected void GvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    protected void RdYear_CheckedChanged(object sender, EventArgs e)
    {
        if (RdYear.Checked)
        {
            lblMonth.Visible = this.DptMonth.Visible = false;
            BtnQuery_Click(this.BtnQuery, new EventArgs());
        }
        else
        {
            lblMonth.Visible = this.DptMonth.Visible = true;
            BtnQuery_Click(this.BtnQuery, new EventArgs());
        }
    }
    protected void BtnDelete_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        new Yipusoft.WorkTaskGrade.BLL.WorkTaskGrade().Delete(new Guid(e.CommandArgument.ToString()));
        BtnQuery_Click(this.BtnQuery, new EventArgs());
    }

    private void BindYearList()
    {
        for (int i = 2008; i <= 2050; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "年";
            li.Value = i.ToString();
            DptYear.Items.Add(li);
        }
    }
}
